<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup">
  <lv-form-item *ngIf="!isDrill">
    <lv-form-label lvRequired>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="restoreLocation">
        <lv-group [lvGutter]="'24px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="rowCopy?.resource_status === 'NOT_EXIST'"
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="restoreLocationType.NEW">
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="formGroup.get('restoreLocation').value === restoreLocationType.ORIGIN"
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'common_location_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <input lv-input type="text" formControlName="originLocation"/>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="formGroup.get('restoreLocation').value === restoreLocationType.NEW"
  >
  <aui-select-tag [formGroup]="formGroup" (updateTable)="updateTable($event)" [targetKey]="'target'"></aui-select-tag>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_target_to_cluster_label' | i18n }}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
        <lv-select
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
          formControlName="target"
          [lvOptions]="targetOptions"
          lvValueKey="value"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
    <!--低版本副本不支持新建实例恢复，因为副本信息里没有存机型配置信息-->
    <lv-form-item *ngIf="!hideCreateInstance">
      <lv-form-label lvRequired>
        {{'protection_restore_instance_select_label'|i18n}}
      </lv-form-label>
      <lv-form-control>
        <lv-radio-group formControlName="instanceStatus">
          <lv-group [lvGutter]="'30px'">
            <lv-radio [lvValue]=InstanceStatus.EXISTED.value>
              {{InstanceStatus.EXISTED.label | i18n}}
            </lv-radio>
            <lv-radio [lvValue]=InstanceStatus.NEW.value>
              {{InstanceStatus.NEW.label | i18n}}
            </lv-radio>
          </lv-group>
        </lv-radio-group>
      </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.get('instanceStatus').value === InstanceStatus.EXISTED.value">
      <lv-form-item>
        <lv-form-label lvRequired>
          {{ 'protection_target_instance_label' | i18n }}
          <i lv-icon="aui-icon-help"
             lv-tooltip="{{'protection_tdsql_non_distributed_restore_instance_tips_label'|i18n}}" lvTooltipTheme="light"
             lvTooltipPosition="top"
             class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
          <lv-select
            lvShowFilter
            lvFilterKey="label"
            lvFilterMode="contains"
            formControlName="instance"
            [lvOptions]="instanceOptions"
            lvValueKey="value"
          >
          </lv-select>
        </lv-form-control>
      </lv-form-item>
    </ng-container>
    <ng-container *ngIf="formGroup.get('instanceStatus').value === InstanceStatus.NEW.value">
      <lv-form-item>
        <lv-form-label lvRequired>{{'protection_disaster_recovery_label' | i18n}}</lv-form-label>
        <lv-form-control>
          <lv-select [lvOptions]="nodeOptions" formControlName="drMode" lvValueKey="value"></lv-select>
        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>
          {{'protection_instance_name_label'|i18n}}
        </lv-form-label>
        <lv-form-control [lvErrorTip]="instanceNameErrorTip">
          <input lv-input formControlName="newInstanceName"/>
        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>
          {{'protection_data_node_label'|i18n}}
        </lv-form-label>
      </lv-form-item>
        <div *ngIf="!!formGroup.get('drMode').value" class="data-node">
          <lv-datatable
            [lvData]="[]"
            [lvFake]="true"
            formArrayName="dataNodes"
          >
            <thead>
            <tr>
              <th>
            <span class="table-head-proxy">
              {{ 'protection_proxy_host_label' | i18n }}
            </span>
              </th>
            </tr>
            </thead>
            <tbody style="min-height: 200px">
            <ng-container *ngFor="let item of dataNodes; let i = index">
              <tr [formGroupName]="i">
                <td>
                  <lv-form-control class="formControl">
                    <aui-agent-select
                      [lvOptions]="proxyOptions"
                      formControlName="parentUuid"
                      lvValueKey="value"
                      [lvShowClear]="true"
                    >
                    </aui-agent-select>
                  </lv-form-control>
                </td>
              </tr>
            </ng-container>
            </tbody>
          </lv-datatable>
        </div>
      <lv-alert lvType="info" lvClosable="false" class="data-node">
        {{'protection_tdsql_restore_data_nodes_tips_label'|i18n}}
      </lv-alert>
      <lv-collapse [lvMultiExpansion]="false" lvType="simple">
        <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="true">
          <div formGroupName="machineInfo">
            <lv-form-item>
              <lv-form-label>
                {{'protection_machine_type_model_label'|i18n}}
              </lv-form-label>
              <lv-form-control>
                <lv-select
                  [lvOptions]="machineOptions"
                  formControlName="machine"
                  lvValueKey="value"
                  lvShowClear
                  lvShowFilter
                  lvFilterMode="contains"
                  lvFilterKey="label"
                >
                </lv-select>
              </lv-form-control>
            </lv-form-item>
            <ng-container *ngIf="!!formGroup.get('machineInfo').get('machine').value">
              <lv-form-item>
                <lv-form-label lvRequired>
                  {{'protection_cpu_core_number_label'|i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="formGroupValidateInfo['cpu'].rangeErrorTips">
                  <input lv-input formControlName="cpu" [placeholder]="formGroupValidateInfo['cpu'].rangePlaceholder">
                </lv-form-control>
              </lv-form-item>
              <lv-form-item>
                <lv-form-label lvRequired>
                  {{'protection_memory_size_label'|i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="formGroupValidateInfo['memory'].rangeErrorTips">
                  <input lv-input formControlName="memory"
                         [placeholder]="formGroupValidateInfo['memory'].rangePlaceholder">
                </lv-form-control>
              </lv-form-item>
              <lv-form-item>
                <lv-form-label lvRequired>
                  {{'protection_data_disk_size_label'|i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="formGroupValidateInfo['dataDisk'].rangeErrorTips">
                  <input lv-input formControlName="dataDisk"
                         [placeholder]="formGroupValidateInfo['dataDisk'].rangePlaceholder">
                </lv-form-control>
              </lv-form-item>
              <lv-form-item>
                <lv-form-label lvRequired>
                  {{'protection_log_disk_size_label'|i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="formGroupValidateInfo['logDisk'].rangeErrorTips">
                  <input lv-input formControlName="logDisk"
                         [placeholder]="formGroupValidateInfo['logDisk'].rangePlaceholder">
                </lv-form-control>
              </lv-form-item>
            </ng-container>
          </div>
        </lv-collapse-panel>
      </lv-collapse>
    </ng-container>
  </ng-container>
</lv-form>

<ng-template #titleTpl>
  <lv-group lvGutter="4px">
    <span class="custom-collapse-title-text">{{'common_advanced_label'|i18n}}</span>
    <i lv-icon="aui-icon-help" lvTooltipTheme="light"
       lv-tooltip="{{ 'protection_tdsql_advanced_tips_label' | i18n }}"
       lvColorState='true'
    >
    </i>
  </lv-group>
</ng-template>


